package fw.qaz.asmx.reader.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import fw.qaz.asmx.reader.R;
import fw.qaz.asmx.reader.adapter.item.BookMarkItem;

public class BookmarkAdapter extends RecyclerView.Adapter<BookmarkAdapter.ViewHolder>
{
    private List<BookMarkItem> lst;

    private OnItemClickListener onItemClickListener;

    public BookmarkAdapter(List<BookMarkItem> lst)
    {
        this.lst = lst;
    }

    @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View v = LayoutInflater.from(parent.getContext())
                               .inflate(R.layout.list_bookmark_item, parent, false);

        return new ViewHolder(v);
    }

    @Override public void onBindViewHolder(ViewHolder vh, int pos)
    {
        BookMarkItem bm = lst.get(pos);
    }

    @Override public int getItemCount()
    {
        return lst.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
    {
        private TextView tvId;
        private TextView tvTitle;
        private TextView tvCommit;

        public ViewHolder(View v)
        {
            super(v);
            tvId = (TextView) v.findViewById(R.id.tv_id);
            tvTitle = (TextView) v.findViewById(R.id.tv_title);
            tvCommit = (TextView) v.findViewById(R.id.tv_commit);
        }

        @Override public void onClick(View v)
        {
            if (onItemClickListener != null)
            {
                int pos = getAdapterPosition();
                onItemClickListener.onItemClick(v, lst.get(pos), pos);
            }
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener)
    {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener
    {
        void onItemClick(View v, BookMarkItem bm, int pos);
    }
}
